package Practice;

public class FindMax {
    public static void main(String[] args) {
        int[] arr=new int[]{1,-2,3,5,-2,6,-1};
        int sumI=arr[0];
        int left=0;
        int max=sumI;
        for(int i=0;i<arr.length;i++){
            if(sumI>=0){ //正数，为正影响
                sumI+=arr[i];
            }else{  //出现和为负数时，就舍弃
                sumI=arr[i];
            }
            if(sumI>max){
                max=sumI;
            }
        }
        System.out.println(max);
    }
}
